<?php
function encuestaPDF($idenc){
  
  include (dirname(dirname(__FILE__)).'/Guardado/crearpdf2.php');
  $host	= "localhost";
	$db	= "autoguayanaBD";
	$user	= "postgres";
	$password = "12345";
        $port = "5432";

	// Abrir la Conexión
        $datos = "host=$host port=$port dbname=$db user=$user password=$password";
        $conex= pg_connect($datos)  or die("Error en conexion".pg_last_error());
        
    $sentencia = "select enc.encabezado, preg.preg
                  from encuesta as enc, encpreg as preg
                  where enc.idenc = $idenc and preg.idenc=$idenc;";
    
    $query = pg_query($conex,$sentencia) or die('Consulta fallida: ' . pg_last_error());
        // Redireccion
        pg_close($conex);

        $tupla = pg_fetch_array($query);
        
        $cuerpo.= "<img src='../img/logo.png' /> <h2>Encuesta Cliente: ".$tupla[0]."</h2>"
            ?>
                                
<?php     
         while ($tupla = pg_fetch_array($query)) {
                    //Guardando tuplas en el pdf
             
                    $cuerpo.= "
                            <br/>
                            <td>  ".$tupla[1]."</td>
                            <br/>    
                            <td>_______________________________________________________________________________________</td>   
                            <td>_______________________________________________________________________________________</td> 
                            <td>_______________________________________________________________________________________</td> 
                            <br/>
                       ";
         }  
                
         crear_pdf($cuerpo,"Encuesta ".$idenc);  
}
?>  